﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SDPChecker
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Count() != 2)
            {
                OutputUsage();
                return;
            }

            var assemblies = new CqlResultParser(new StreamReader(args[0])).InstableAssemblies.ToList();
            var dependencies = new DependenciesParser(new StreamReader(args[1]));
            var checker = new StableDependenciesPrincipleChecker(assemblies, dependencies.GetDependencies(assemblies.Select(a => a.Name)));

            if (checker.BadBoysFound)
            {
                Console.WriteLine("ZOMG!!!!");
                Console.WriteLine("One or more stable-dependencies principle offender found");
                Console.WriteLine("Fix the following before the ALM team notice, hunt you down and give you your well deserved punishment\r\n");
                checker.BadBoys.ToList().ForEach(OutputBadBoy);
            }

            Console.WriteLine("Press any key to exit, if you can't find it press the spacebar (the big one)");
            Console.ReadKey();
        }

        private static void OutputUsage()
        {
            Console.WriteLine("Usage: SPDChecker <path to CQLResult.xml> <path to AssembliesDependencies.xml>");
            Console.WriteLine("Both files are usually located in the folder NDependOut in the folder where your nDepend project is located");
        }

        private static void OutputBadBoy(AssemblyInfo badboy)
        {
            Console.WriteLine(badboy.ToOutputString());
        }
    }
}
